<h2><?= $title ?></h2>
<div class="mb-3">
  <a href="<?= site_url('news/new') ?>" class="btn btn-primary">
    <i class="bi bi-plus-circle"></i> Add News Item
  </a>
</div>

<?php if (! empty($news) && is_array($news)) : ?>

    <!-- 折叠面板容器 -->
<div class="accordion" id="newsAccordion">
  <?php foreach ($news as $newsItem): ?>
    <!-- 单条新闻折叠项（同步骤3中的循环内容） -->
    <div class="accordion-item">
      <h2 class="accordion-header" id="heading-<?= $newsItem['id'] ?>">
        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-<?= $newsItem['id'] ?>">
          <?= $newsItem['title'] ?>
        </button>
      </h2>
      <div id="collapse-<?= $newsItem['id'] ?>" class="accordion-collapse collapse" data-bs-parent="#newsAccordion">
        <div class="accordion-body">
          <p><?= $newsItem['body'] ?></p>
          <a href="<?= site_url('news/view/' . $newsItem['id']) ?>" class="btn btn-sm btn-info me-2">
            <i class="bi bi-eye"></i> View article
          </a>
          <a href="<?= site_url('news/delete/' . $newsItem['id']) ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure to delete this news?')">
            <i class="bi bi-trash3"></i> Delete
          </a>
        </div>
      </div>
    </div>
  <?php endforeach; ?>
</div>

<?php else : ?>

    <h3>No News</h3>
    <p>Unable to find any news for you.</p>

<?php endif ?>